﻿using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMS_Master.RabbitMQ
{
    public class MqSingleCase
    {
        public static ConnectionFactory factory = new ConnectionFactory() { HostName = "localhost", UserName = "guest", Password = "guest", Port = 5672 };
        public static IConnection connection = null;
        public static IModel channel = null;


        // 定义一个标识确保线程同步
        private static readonly object locker = new object();
        // 定义私有构造函数，使外界不能创建该类实例
        private MqSingleCase()
        {
            lock (locker)
            {
                // 如果类的实例不存在则创建，否则直接返回
                if (connection == null)
                {
                    connection = factory.CreateConnection();
                    channel = connection.CreateModel();
                }
            }
        }
    }
}
